<?php
session_start();
// validação
include "../connections/cadastro.php";

if(!$_POST[login]){
$erro .= "Preencha o campo login";	
}
if(!$_POST[senha]){
$erro .= "Preencha o campo Senha";	
}

if($erro){
echo "<script>";
echo "window.location='login.php?erro=Usuário ou senha inválida!';";
echo "</script>";

}else{

$consLogin = "SELECT COUNT(idusuarioAdm) AS total
FROM usuarioadm
WHERE login='".$_POST[login]."' 
AND senha='".$_POST[senha]."'";

$result = $mysqli->query($consLogin);
$row = $result->fetch_array(MYSQLI_NUM);

if($row[0]==1){

$consLogin = "SELECT * 
FROM usuarioadm 
WHERE login='".$_POST[login]."'
AND senha='".$_POST[senha]."'";

$result = $mysqli->query($consLogin);
$row2 = $result->fetch_array(MYSQLI_ASSOC);

//

$_SESSION[usuario][idusuarioAdm] = $row2["idusuarioAdm"]; 
$_SESSION[usuario][login] = $row2["login"]; 
$_SESSION[usuario][nome] = $row2["nome"];
$_SESSION[usuario][tipo] = $row2["tipo"]; 

echo "<script>";
echo "window.location='index.php';";
echo "</script>";

}else{
echo "<script>";
echo "window.location='login.php?erro=Usuário ou senha inválida!';";
echo "</script>";	

}
}
?>